import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import authApi from '@/api/auth'

type LoginUser = {
  userName:string,
  token:string
}
export const useLoginUserStore = defineStore('LoginUser', () => {
  const LoginUser = ref<LoginUser>()

  const login = (userName:string, password:string) => {
    return authApi.login(userName,password)
  }
  const isLogin = () => {
    return LoginUser.value
  }
  const setUser = (user:LoginUser) => {
    LoginUser.value = user
  }
  const getToken = () => {
    return LoginUser.value?.token
  }
  const getUserName = () => {
    return LoginUser.value?.userName
  }
  return { login, isLogin, setUser, getToken, getUserName }
})
